home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
426-450
/
disk_429
/
dr
/
forevery_and_whichever
< prev
next >
Wrap
Text File
|
1992-05-06
|
3KB
|
51 lines
FOREVERY and WHICHEVER
These are two related small utilities. Each takes a CLI command on its
argument line, with a place marked in it with [] like in an alias. Each
reads its standard input (use redirection to send a file into it) and
substitutes a line of the input file into the command at the point marked by
[]. ForEvery executes the command once for every line in the input file,
except blank lines or lines that make the command more than 255 characters
long, and Whichever picks a single line of the input file at random and
substitutes that into the command and executes it.
Generally the input file would be a list of filenames, one per line. The
command would do something with that file. For instance you might want to
mark some files as archived. You'd put the list of files in a file called,
for instance, T:arch, and give the command
ForEvery < T:Arch Protect [] +a
Dr is a good program for generating lists of files one per line, using its -o
option. Rls by Donald Kindred works similarly. The use I wrote Whichever
for was so that I would never know what sound my computer would use for a
beep after a reboot. I put a list of IFF sound files into the file Bleeps,
and include in my startup-sequence the command
Whichever < Bleeps InstallBeep []
Whichever, unlike ForEvery, reads the entire input file into memory, so don't
use too enormous a file. In fact it cannot read more than 1000 lines. Like
ForEvery, it rejects any line that would make the command more than 255
characters long.
One bad feature of ForEvery: it would be nice if you could stop it with
control-C or control-D, but when you redirect input the CLI makes the program
unable to hear those signals! I looked for a workaround but didn't find one.
So this version of the program can't be stopped in the middle.
There is some preparation you should set up to get the best performance out
of ForEvery, or for that matter out of any program that uses the DOS
Execute() function. Older versions of Execute() always loaded the Run
program from disk every time. Now that's no longer necessary, if the
following conditions are met: the Run program has been made resident, you
are using 1.3 or newer ROM/Kickstart, and (if your ROM is 1.3) you have run
the 1.3.2 version of SetPatch. The 1.3.0 SetPatch won't do. If you do not
have 1.3.2, get it, or just get its SetPatch! Many many programs will run
quicker and easier. It also helps to have L:Shell-Seg resident, if the
command that is being fed to Execute() calls a program that is residentable.
ForEvery is pure (residentable), but Whichever is not. Both are in the
public domain, written by Paul Kienitz.